package com.xmqian.app.project.ui.preview.activity;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.coszero.ui.recycler.RecyclerDiverUtils;
import com.coszero.utils.base.BaseRecyclerAdapter;
import com.coszero.utils.base.BaseRecyclerViewHolder;
import com.coszero.utils.utils.ResourceUtils;
import com.xmqian.app.project.common.base.BaseMyActivity;
import com.xmqian.kotlinApp.R;
import com.xmqian.kotlinApp.databinding.ActivityPagePreviewBinding;

import java.util.ArrayList;
import java.util.List;

public class PagePreviewActivity extends BaseMyActivity {

    private ActivityPagePreviewBinding binding;


    public static void startActivity(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, PagePreviewActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected View getLayoutView() {
        binding = ActivityPagePreviewBinding.inflate(getLayoutInflater());
        EdgeToEdge.enable(this);
        ViewCompat.setOnApplyWindowInsetsListener(binding.getRoot(), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        return binding.getRoot();
    }

    @Override
    public void initView() {
        List<String> list = new ArrayList<>();
        list.add("预览界面1");
        list.add("预览界面2");
        list.add("预览界面3");
        list.add("预览界面4");
        list.add("预览界面5");
        binding.rvContent.setLayoutManager(new LinearLayoutManager(mActivity));
        binding.rvContent.addItemDecoration(RecyclerDiverUtils.hDiver(mActivity));
        BaseRecyclerAdapter baseRecyclerAdapter = new BaseRecyclerAdapter<BaseRecyclerViewHolder>(this, list) {
            @NonNull
            @Override
            public BaseRecyclerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                return new BaseRecyclerViewHolder(mActivity, View.inflate(mActivity, android.R.layout.simple_list_item_1, null));
            }

            @Override
            public void onBindViewHolder(@NonNull BaseRecyclerViewHolder holder, int position) {
                holder.getTextView(android.R.id.text1).setText((CharSequence) list.get(position));
                holder.getTextView(android.R.id.text1).setTextColor(ResourceUtils.getColor(mContext, R.color.black));
            }

            @Override
            public int getItemCount() {
                return list.size();
            }
        };
        binding.rvContent.setAdapter(baseRecyclerAdapter);
    }

    @Override
    protected void initData() {

    }
}